#include <bits/stdc++.h>

using namespace std;

int main()
{
    int object_num = 0;
    int bag_weight = 0;
    cin >> object_num >> bag_weight;
    vector<int> object_weight(object_num, 0);
    vector<int> object_value(object_num, 0);
    for (int i = 0; i < object_num; i++)
    {
        cin>>object_weight[i]>>object_value[i];
    }
    vector<int> dp(bag_weight+1,0);
    for(int i=0;i<object_num;i++)
    {
        for(int j=object_weight[i];j<=bag_weight;j++)
        {
            dp[j]=max(dp[j],dp[j-object_weight[i]]+object_value[i]);
        }
    }
    cout<<dp[bag_weight]<<endl;
    return 0;
}